<!--
 * @description  : 案件-互联网信息
 * @descriptionDetail: 案件-互联网信息
 * @copyright    : 浙江烟草
 * @author       : sy
 * @create       : 2022-07-12 21:31:06
-->
<template>
  <view class="pages">
    <!-- #ifdef H5-ONLY -->
    <theme-navbar
      :is-white="false"
      :title="navTitle"
      :custom-back="goBack"
      back-text="返回"
      style="z-index: 99999"
    >
    </theme-navbar>
    <!-- #endif -->
    <view class="content">
      <u-form :model="form" label-width="auto" :error-type="errorType" :label-style="lab_style" ref="uForm">
        <u-form-item label="信息分类" label-position="top" :required="true" prop="infoTypeName">
          <dic-input 
            :keyWord="$u.dic.DIC_KEYS.INFO_TYPE" 
            :dicCode="form.infoType" 
            type="select" 
            :border="border" 
            :select-open="dicSelectOpen($u.dic.DIC_KEYS.INFO_TYPE)" 
            placeholder="请选择" 
            v-model="form.infoTypeName" 
            @changeInputModelData="(name)=>{$set(form, 'infoTypeName', name)}" 
            @click="!isDisabled && showDic($u.dic.DIC_KEYS.INFO_TYPE,form.infoType)" 
          />
        </u-form-item>
        <u-form-item label="信息项:" prop="infoItem" label-position="top" :required="true">
          <u-input placeholder="" :disabled="isDisabled" v-model="form.infoItem" />
        </u-form-item>
        <u-form-item label="信息内容:" prop="infoContent" label-position="top">
          <u-input placeholder="" :disabled="isDisabled" type="textarea" v-model="form.infoContent" />
        </u-form-item>
      </u-form>
      <!-- 数据字典 -->
      <dic-choice 
        :keyWord="dicKeyWords" 
        :currentSelect="dicCurrentSelect" 
        v-model="dicShow" 
        @confirm="selectDicConfirm"
      ></dic-choice>
    </view>
    <view class="submit-btns btn-other-cls">
      <u-button class="u-btn" type="primary" v-if="!isDisabled" @click="saveInterBtn">
        保存
      </u-button> 
    </view>
  </view>
</template>

<script>
import caseService from '@/service/case/case.service.js';
import DicChoice from "@/components/dic_choice.vue";
import DicInput from "@/components/dic_input.vue";
export default {
  components:{
    DicInput,
    DicChoice,
  },
  data(){
    return{
      form:{
        infoItem:"",
        infoContent:"",
        infoType:"",
        infoTypeName:"",
        partyUuid:"",
        partyExUuid:"",
      },
      errorType: ['border-bottom','message',],
      lab_style:{
        fontWeight: 500,
        color: this.$theme.u_main_color,
        fontSize: '.75rem',
      },
      border: false,
      dicShow: false, // dic_select 是否显示
      dicKeyWords: "", // dic 关键字
      dicCurrentSelect: "", // dic 当前选择项
      rules:{
        infoTypeName: [{
          required: true,
          message: '请选择信息分类',
          trigger: 'change',
        },],
        // 名称
        infoItem: [{
          required: true,
          message: '请输入信息',
          trigger: ['change', 'blur',],
        },],},
      newObj:{},
      isDisabled:false, // 表单是否禁用
    }
  },
  onReady() {
    this.$refs.uForm.setRules(this.rules);
  },
  onLoad(opt){
    let obj = this.getRouteParam();
    this.form.partyUuid = obj.caseUuid;
    if (obj.type) {
      // 查看详情表单禁用
      if(obj.type === 'view'){
        this.isDisabled = true;
      }
    }
    // 表单处理
    if(obj.param){
      this.objMerge(this.form, obj.param);
    }
    console.log(obj)
  },
  methods:{
    // 数据字典组件选择事件
    dicSelectOpen: function (keyWords) {
      if (this.dicKeyWords == keyWords && this.dicShow) {
        return true;
      }
      return false;
    },
    showDic: function (key, cur) {
      if (this.dicShow) return;
      this.dicKeyWords = key;
      this.dicCurrentSelect = cur;
      this.dicShow = true;
    },
    selectDicConfirm: function (e) {
      // 类型
      if (this.dicKeyWords == this.$u.dic.DIC_KEYS.INFO_TYPE) {
        this.form.infoTypeName = e[0].label;
        this.form.infoType = e[0].extra.bcbCode;
      }
    },
    saveInterBtn(){
      let self = this;
      this.$refs.uForm.validate(valid => {
        if (valid) {
          let {...params} = self.form
          caseService.saveInternet(params).then(res => {
            if(res.success){
              this.$u.toast(res.msg);
              self.backPrev({
                paramKey: "internetInfo",
                param : true,
              });
            }else{
              this.$u.toast('保存失败');
            }
          }).catch(err => {
            this.$u.toast(err);
          })
        } else {
          console.log('表单验证失败');
        }
      });
    },
  },
}
</script>

<style lang="scss" scoped>
@import "../case_common.scss";
.content{
  padding: 4rpx 34rpx;
}
</style>